﻿package mortal.game.view.autoArena.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.common.*;
    import mortal.mvc.interfaces.*;

    public class AutoArenaResultWinNew extends ResultBaseWindow
    {
        private var _winInfoSpr:GSprite;
        private var _failInfoSpr:GSprite;
        private var _selfName:GTextFiled;
        private var _selfRankIcon:GImageBitmap;
        private var _selfArrow:GBitmap;
        private var _selfRank:GTextFiled;
        private var _vsIcon:GImageBitmap;
        private var _otherName:GTextFiled;
        private var _otherRankIcon:GImageBitmap;
        private var _otherArrow:GBitmap;
        private var _otherRank:GTextFiled;
        private var _upOrDown:GTextFiled;
        private var _exp:GTextFiled;
        private var _gold:GTextFiled;
        private static var _instance:AutoArenaResultWinNew;

        public function AutoArenaResultWinNew(param1:ILayer = null)
        {
            super(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._winInfoSpr = UICompomentPool.getUICompoment(GSprite);
            this._winInfoSpr.x = 210;
            this._winInfoSpr.y = 46 - 7;
            this.addChild(this._winInfoSpr);
            this._selfName = UIFactory.gTextField("", 3 + 4, 0, 106, 20, this._winInfoSpr);
            this._selfRankIcon = UIFactory.gImageBitmap(ImagesConst.AutoArena_Rank, 0 + 4, 23, this._winInfoSpr);
            this._selfArrow = UIFactory.gBitmap(ImagesConst.upgradeArrow, 37 + 4, 24 + 4, this._winInfoSpr);
            this._selfRank = UIFactory.gTextField("", 53 + 4, 24 - 2, 37, 20, this._winInfoSpr, GlobalStyle.textFormatLv.setSize(14));
            this._vsIcon = UIFactory.gImageBitmap(ImagesConst.AutoArena_VsIcon, 112, -8, this._winInfoSpr);
            this._otherName = UIFactory.gTextField("", 193 + 7 + 4, 0, 106, 20, this._winInfoSpr);
            this._otherRankIcon = UIFactory.gImageBitmap(ImagesConst.AutoArena_Rank, 193 + 4 + 4, 23, this._winInfoSpr);
            this._otherArrow = UIFactory.gBitmap(ImagesConst.upgradeArrow, 227 + 6 + 4, 24 + 4, this._winInfoSpr);
            this._otherRank = UIFactory.gTextField("", 242 + 4 + 4, 24 - 2, 37, 20, this._winInfoSpr, GlobalStyle.textFormatHong.setSize(14));
            this._winInfoSpr.visible = false;
            this._failInfoSpr = UICompomentPool.getUICompoment(GSprite);
            this._failInfoSpr.x = 272 - 25;
            this._failInfoSpr.y = 46;
            this.addChild(this._failInfoSpr);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.AutoArena_FailRank, 0, 0, this._failInfoSpr));
            this.pushUIToDisposeVec(UIFactory.bg(250 - 14, 106 - 3, 233 - 8, 25, this, ImagesConst.RegionTitleBg));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40887), 350 - 31, 111 - 5 - 3, 70, 25, this, GlobalStyle.textFormatHuang.setSize(15)));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.AutoArena_YourRank, 290 - 32, 144 - 6, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.AutoArena_GetRewardTxt, 290 - 32, 173 - 6, this));
            this._upOrDown = UIFactory.gTextField("", 361 - 17, 146 - 6, 110, 20, this);
            this._exp = UIFactory.gTextField("", 361 - 17, 176 - 8, 110, 20, this, GlobalStyle.textFormatChen);
            this._gold = UIFactory.gTextField("", 361 - 17, 194 - 8, 110, 20, this, GlobalStyle.textFormatChen);
            this._winInfoSpr.visible = false;
            this._failInfoSpr.visible = false;
            setContentBgSize(233, 116 + 16);
            return;
        }// end function

        override protected function enterBtnClickHandler(event:MouseEvent) : void
        {
            if (GameMapUtil.curMapState.isAutoArenaMap)
            {
                GameProxy.copy.leaveCopy();
            }
            hide();
            return;
        }// end function

        override protected function addTypeBg() : void
        {
            _typeBg = UIFactory.gImageBitmap(ImagesConst.ResultWinTypeBg, 0, 0, this, this.onBgLoadCompl);
            return;
        }// end function

        private function onBgLoadCompl() : void
        {
            _typeBg.height = 52;
            return;
        }// end function

        override protected function updateSize() : void
        {
            super.updateSize();
            if (_contentBg)
            {
                _contentBg.y = _contentBg.y + 21;
            }
            return;
        }// end function

        private function updateResultInfo() : void
        {
            var _loc_1:SAutoArenaResult = null;
            var _loc_2:Array = null;
            var _loc_3:int = 0;
            _loc_1 = Cache.instance.autoArena.sAutoArenaResult;
            if (_loc_1)
            {
                if (_loc_1.isWin)
                {
                    resultType = ResultBaseWindow.showSuccess;
                    this._winInfoSpr.visible = true;
                    _loc_3 = _loc_1.newRank - _loc_1.oldRank;
                    this._selfName.text = Cache.instance.role.entityInfo.name;
                    this._selfArrow.bitmapData = GlobalClass.getBitmapData(ImagesConst.upgradeArrow);
                    this._selfRank.text = Math.abs(_loc_3) + "";
                    this._otherName.text = _loc_1.toEntityName;
                    this._otherArrow.bitmapData = GlobalClass.getBitmapData(ImagesConst.downArrow);
                    this._otherRank.text = Math.abs(_loc_3) + "";
                    if (_loc_3 < 0)
                    {
                        this._upOrDown.htmlText = Language.getStringByParam(40888, _loc_1.newRank);
                    }
                    if (_loc_3 > 0)
                    {
                        this._upOrDown.htmlText = Language.getStringByParam(40889, _loc_1.newRank);
                    }
                    if (_loc_3 == 0)
                    {
                        this._upOrDown.htmlText = HTMLUtil.addColor(Language.getString(40890), GlobalStyle.colorLv);
                    }
                }
                else
                {
                    resultType = ResultBaseWindow.showFail;
                    this._failInfoSpr.visible = true;
                    this._upOrDown.htmlText = HTMLUtil.addColor(Language.getString(40890), GlobalStyle.colorLv);
                }
                _loc_2 = AutoArenaRewardConfig.instance.getInfosByType(4);
                if (_loc_1.isWin && _loc_2.length > 0)
                {
                    this._exp.text = Language.getStringByParam(40891, (_loc_2[0] as TAutoArenaReward).exp + "");
                }
                if (_loc_1.gold > 0)
                {
                    this._gold.text = Language.getStringByParam(40892, _loc_1.gold);
                }
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            this.updateResultInfo();
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._winInfoSpr.dispose();
            this._winInfoSpr = null;
            this._failInfoSpr.dispose();
            this._failInfoSpr = null;
            this._selfName.dispose();
            this._selfName = null;
            this._selfRankIcon.dispose();
            this._selfRankIcon = null;
            this._selfArrow.dispose();
            this._selfArrow = null;
            this._selfRank.dispose();
            this._selfRank = null;
            this._vsIcon.dispose();
            this._vsIcon = null;
            this._otherName.dispose();
            this._otherName = null;
            this._otherRankIcon.dispose();
            this._otherRankIcon = null;
            this._otherArrow.dispose();
            this._otherArrow = null;
            this._otherRank.dispose();
            this._otherRank = null;
            this._upOrDown.dispose();
            this._upOrDown = null;
            this._exp.dispose();
            this._exp = null;
            this._gold.dispose();
            this._gold = null;
            return;
        }// end function

        public static function get instance() : AutoArenaResultWinNew
        {
            if (_instance == null)
            {
                _instance = new AutoArenaResultWinNew;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
